package com.brkj.personalCenter;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import com.brkj.httpInterface.BaseAjaxParams;
import com.brkj.httpInterface.HttpInterface;
import com.brkj.main.R;
import com.brkj.personalCenter.mode.DS_Notice;
import com.brkj.test.model.DS_Exam;
import com.brkj.util.MyAjaxCallBack;
import com.brkj.util.MyApplication;
import com.brkj.util.view.BaseActivity;
import com.brkj.util.view.BaseCoreActivity;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import net.tsz.afinal.FinalHttp;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by colin.ding on 2014/5/26.
 */
public class NoticeActivity extends BaseActivity{
    private ListView listView;
    private TextView noContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setAnimType(RIGHT_ENTER_LEFT_EXT);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notice);

        setActivityTitle("系统公告");
        setReturnBtn();

        listView = (ListView)findViewById(R.id.listView);
        noContent = (TextView)findViewById(R.id.noContent);

        getNotice();
    }

    private void getNotice() {
        BaseAjaxParams params = new BaseAjaxParams();
        params.put(HttpInterface.HIF_GetNotice.params.UserID, MyApplication.myUserID);
        params.put(HttpInterface.HIF_GetNotice.params.NoticeID, "0");

        FinalHttp fh = new FinalHttp();
        fh.post(HttpInterface.HIF_GetNotice.address, params, new MyAjaxCallBack<Object>((BaseCoreActivity)this) {
            @Override
            public void onSuccess(Object o) {
                super.onSuccess(o);

                Gson gson = new Gson();
                Type listType = new TypeToken<List<DS_Notice>>(){}.getType();
                List<DS_Notice> noticeList  = gson.fromJson((String)o, listType);

                List<HashMap<String, String>> NoticeMapList =  new ArrayList<HashMap<String, String>>();
                for(DS_Notice notice: noticeList){
                    HashMap<String, String> map = new HashMap<String, String>();
                    map.put("title", notice.getTitle());
                    map.put("content", notice.getContent());
                    map.put("time", notice.getTime());

                    NoticeMapList.add(map);
                }


                listView.setAdapter(new SimpleAdapter(NoticeActivity.this,NoticeMapList,
                        R.layout.notice_item, new String[]{"title", "content", "time"},
                        new int[]{R.id.title, R.id.content, R.id.time}));
            }
        });
    }
}
